<template>
    <div>
        <mixinsObj></mixinsObj>
        <el-card>
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-input placeholder="请输入内容" class="input-with-select" clearable>
                        <el-button slot="append" icon="el-icon-search"></el-button>
                    </el-input>
                </el-col>
                <el-table :data="tableData" border style="width: 100%">
                    <el-table-column type="index" label="#">
                    </el-table-column>
                    <el-table-column prop="order_number" label="订单编号" width="200px">
                    </el-table-column>
                    <el-table-column prop="order_price" label="订单价格">
                    </el-table-column>
                    <el-table-column label="是否付款">
                        <template slot-scope="scope">
                            <el-tag v-if="scope.row.pay_status == 0" type="danger">未付款</el-tag>
                            <el-tag v-if="scope.row.pay_status == 1" type="success">已付款</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column prop="is_send" label="是否发货">
                    </el-table-column>
                    <el-table-column label="创建时间">
                        <template slot-scope="scope">
                            {{ parseTime(scope.row.update_time) }}
                        </template>
                    </el-table-column>

                    <el-table-column prop="address" label="操作">
                        <el-button type="primary" icon="el-icon-edit" circle size="mini"></el-button>
                        <el-button type="success" icon="el-icon-check" circle size="mini"></el-button>
                    </el-table-column>
                </el-table>
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                    :current-page="query.pagenum" :page-sizes="[3, 5, 8, 10]" :page-size="query.pagesize"
                    layout="total, sizes, prev, pager, next, jumper" :total="total">
                </el-pagination>
            </el-row>
        </el-card>

    </div>
</template>
<script>
import mixinsObj from '@/views/mixins.vue'
import { getOrders } from '@/utils/orders'
export default {
    components: { mixinsObj },
    data() {
        return {
            query: {
                query: '',
                pagesize: 5,
                pagenum: 1,
                user_id: '',
                pay_status: '',
                is_send: '',
                order_fapiao_title: '',
                order_fapiao_company: '',
                order_fapiao_content: '',
                consignee_addr: ''
            },

            tableData: [],
            total: 0
        }
    },
    methods: {
        async getTableData() {
            let { data: res } = await getOrders(this.query)
            this.tableData = res.data.goods
            this.total = res.data.total
        },
        parseTime(time, cFormat) {
            if (arguments.length === 0) {
                return null;
            }
            const format = cFormat || "{y}-{m}-{d} {h}:{i}:{s}";
            let date;
            if (typeof time === "object") {
                date = time;
            } else {
                if (typeof time === "string" && /^[0-9]+$/.test(time)) {
                    time = parseInt(time);
                }
                if (typeof time === "number" && time.toString().length === 10) {
                    time = time * 1000;
                }
                date = new Date(time);
            }
            const formatObj = {
                y: date.getFullYear(),
                m: date.getMonth() + 1,
                d: date.getDate(),
                h: date.getHours(),
                i: date.getMinutes(),
                s: date.getSeconds(),
                a: date.getDay(),
            };
            const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
                const value = formatObj[key];
                // Note: getDay() returns 0 on Sunday
                if (key === "a") {
                    return ["日", "一", "二", "三", "四", "五", "六"][value];
                }
                return value.toString().padStart(2, "0");
            });
            return time_str;
        },
        handleSizeChange(val) {
            this.query.pagesize = val
            this.getTableData()
        },
        handleCurrentChange(val) {
            this.query.pagenum = val
            this.getTableData()
        }
    },
    mounted() {
        this.getTableData()
    }
}
</script>